{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F:\\anaconda\\lib\\site-packages\\sklearn\\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.\n",
      "  \"This module will be removed in 0.20.\", DeprecationWarning)\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import lightgbm as lgb\n",
    "import matplotlib.pyplot as plt\n",
    "import gc\n",
    "from sklearn.preprocessing import MinMaxScaler, StandardScaler\n",
    "import seaborn as sns\n",
    "from sklearn.model_selection import KFold, cross_val_score, train_test_split\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.preprocessing import OneHotEncoder,LabelEncoder\n",
    "from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer\n",
    "import time\n",
    "import datetime\n",
    "from sklearn.cross_validation import StratifiedKFold\n",
    "from sklearn.metrics import roc_auc_score, log_loss\n",
    "from scipy import sparse\n",
    "from tqdm import tqdm_notebook\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载数据\n",
    "train = pd.read_table('../data/round1_iflyad_train.txt')\n",
    "test = pd.read_table('../data/round1_iflyad_test_feature.txt')\n",
    "# 合并训练集，验证集\n",
    "data = pd.concat([train,test],axis=0,ignore_index=True)\n",
    "data['click'] = data['click'].fillna(-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 特征工程-数据清洗、特征构建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def process(data):\n",
    "    # 缺失值填充\n",
    "    data['make'] = data['make'].fillna(str(-1))\n",
    "    data['model'] = data['model'].fillna(str(-1))\n",
    "    data['osv'] = data['osv'].fillna(str(-1))\n",
    "    data['app_cate_id'] = data['app_cate_id'].fillna(-1)\n",
    "    data['app_id'] = data['app_id'].fillna(-1)\n",
    "    data['user_tags'] = data['user_tags'].fillna(str(-1))\n",
    "    data['f_channel'] = data['f_channel'].fillna(str(-1))\n",
    "    #数据预处理\n",
    "    data['model'] = data['model'].apply(lambda x: str(x).lower())\n",
    "    data['make'] = data['make'].apply(lambda x: str(x).lower())\n",
    "    #这个因为是url编码的缘故，考虑存在相同的特殊符号可能存在某种联系\n",
    "    a1= data.model.apply(lambda x: '+' if '+' in str(x) else \n",
    "                         '-' if '-' in str(x) else \\\n",
    "                         '_' if '_' in str(x) else \\\n",
    "                         ',' if ',' in str(x) else \\\n",
    "                         'chinese' if u'[\\u4E00-\\u9FA5]' in str(x) else \\\n",
    "                         '%2b' if '%2b' in str(x) else \\\n",
    "                         '%20' if '%20' in str(x) else \\\n",
    "                         '%2522' if '%2522' in str(x) else \\\n",
    "                         '%25' if '%25' in str(x) else \\\n",
    "                         'other')\n",
    "    data['sim_ip'] = a1\n",
    "\n",
    "    #make字段异常值清洗\n",
    "    new = data[['make', 'model', 'instance_id']]\n",
    "    new['make_model'] = new['make']+':::'+new['model']\n",
    "    for i in ['apple', 'oppo', 'vivo', 'huawei', 'lenovo', 'zte', 'xiaomi', 'meizu', 'gionee', 'samsung', 'honor', '360', 'lemobile',\\\n",
    "              'zte', 'letv', 'cmdc', 'hisense', 'oneplus', 'nubia', 'yulong', 'smartisan', 'coolpad', 'doov', 'bbk', 'xiaolajiao',  \\\n",
    "              'le', 'koobee', 'blephone', 'meitu', 'sprd', 'alps', 'konka', 'leeco', 'sugar', 'lephone', 'zuk', 'pa', 'htc',  \\\n",
    "              'yufly', 'tcl', 'ipad', 'changhong', 'sony', 'android', 'sm', 'yufly', 'mha', 'motorola', 'bln', 'vtr',    \\\n",
    "              'asus', '4g', 'ivvi', 'lge', 'qingcheng', 'qiku', 'kopo', 'saga']:\n",
    "        length = len(i)\n",
    "        new['make_model'] = new['make_model'].apply(lambda x: i if ((len(x.split(':::')) > 1) and  ((x.split(':::')[0][:length] == i) | (x.split(':::')[1][:length] == i))) else x)\n",
    "        new['make_model'] = new['make_model'].apply(lambda x: i if ((len(x.split(':::')) > 1) and  ((i in x.split(':::')[0]) | (i in x.split(':::')[1]))) else x)\n",
    "    new['make_model'] = new['make_model'].apply(lambda x: 'apple' if x[:6] == 'iphone' else x)\n",
    "    new['make_model'] = new['make_model'].apply(lambda x: 'xiaomi' if 'mi' in x else x)\n",
    "    new['make_model'] = new['make_model'].apply(lambda x: 'apple' if 'phone' in x else x)\n",
    "    new['make_model'] = new['make_model'].apply(lambda x: 'apple' if 'ios' in x else x)\n",
    "    new['make_model'] = new['make_model'].apply(lambda x: 'meizu' if 'mx' in x else x)\n",
    "    new.loc[new.make_model.isin((new.make_model.value_counts()[new.make_model.value_counts() <= 200]).index), 'make_model'] = 'other' #去除低频词\n",
    "    data['clear_make'] = new['make_model'].copy()\n",
    "    print('make变量处理完毕')\n",
    "\n",
    "    #model字段异常值清洗，正则表达式处理\n",
    "    import re\n",
    "    a = data['model'].copy()\n",
    "    data.loc[data.model.isnull(), 'model'] = 'oppoa7'   ##用众数填充\n",
    "    a = a.apply(lambda x: re.sub(r'[%20]',\"\",x))\n",
    "    a = a.apply(lambda x: re.sub(r'[%252525252525252b]',\"\",x))\n",
    "    a = a.apply(lambda x: re.sub(r'[%25252b]',\"\",x))\n",
    "    a = a.apply(lambda x: re.sub(r'[%25252525252b]',\"\",x))\n",
    "    a = a.apply(lambda x: re.sub(u'[\\u4E00-\\u9FA5]',\"chinese\",x))\n",
    "    a = a.apply(lambda x: re.sub(r' ',\"\",x))\n",
    "    a = a.apply(lambda x: re.sub(r'[+,-_mtk]',\"\",x))\n",
    "    for i in range(12):\n",
    "        a = a.apply(lambda x: 'vivoy'+str(i) if 'vivoy'+str(i) in x else x )\n",
    "        a = a.apply(lambda x: 'vivox'+str(i) if 'vivox'+str(i) in x else x )\n",
    "        a = a.apply(lambda x: 'vivoxplay'+str(i) if 'vivoxplay'+str(i) in x else x )\n",
    "        a = a.apply(lambda x: 'oppoa'+str(i) if 'oppoa'+str(i) in x else x )\n",
    "        a = a.apply(lambda x: 'oppor'+str(i) if 'oppor'+str(i) in x else x )\n",
    "        a = a.apply(lambda x: 'huaweip'+str(i) if 'huaweip'+str(i) in x else x )\n",
    "        a = a.apply(lambda x: 'iphone'+str(i) if 'iphone'+str(i) in x else x )\n",
    "    a = a.apply(lambda x: 'iphone8' if 'iphone8' in x else x )\n",
    "    data['clear_model'] = a\n",
    "    data.loc[data.clear_model.isin(a.value_counts()[a.value_counts() < 300].index), 'clear_model'] = data.loc[data.clear_model.isin(a.value_counts()[a.value_counts() < 300].index), 'clear_model'].apply(lambda x: x[:-1])\n",
    "    for i in ['apple', 'oppo', 'vivo', 'huawei', 'lenovo', 'zte', 'xiaomi', 'meizu', 'gionee', 'samsung', 'honor', '360', 'lemobile',     'zte', 'letv', 'cmdc', 'hisense', 'oneplus', 'nubia', 'yulong', 'smartisan', 'coolpad', 'doov', 'bbk', 'xiaolajiao',     'le', 'koobee', 'blephone', 'meitu', 'sprd', 'alps', 'konka', 'leeco', 'sugar', 'lephone', 'zuk', 'pa', 'htc',     'yufly', 'tcl', 'ipad', 'changhong', 'sony', 'android', 'sm', 'yufly', 'mha', 'motorola', 'bln', 'vtr',      'asus', '4g', 'ivvi', 'lge', 'qingcheng', 'qiku', 'kopo', 'saga']:\n",
    "        data.loc[data.clear_model.isin(data.clear_model.value_counts()[data.clear_model.value_counts() < 300].index), 'clear_model'] =  data.loc[data.clear_model.isin(data.clear_model.value_counts()[data.clear_model.value_counts() < 300].index), 'clear_model'].apply(lambda x: i if i in x else x)\n",
    "    data.loc[data.clear_model.isin((data.clear_model.value_counts()[data.clear_model.value_counts() <= 300]).index), 'clear_model'] = 'other'\n",
    "    print('model 变量处理完毕')\n",
    "\n",
    "    #对于操作系统的处理\n",
    "    import re\n",
    "    new = data[['osv', 'instance_id']]\n",
    "    new.loc[new.osv.isnull(), 'osv'] = '6.0.1'\n",
    "    new['osv'] = new['osv'].apply(lambda x: str(x).lower())\n",
    "    new['digit_osv'] = new['osv'].apply(lambda x: re.findall(r\"\\d+\\.\\d+\\.\\d*\",x)[0] if len(re.findall(r\"\\d+\\.\\d+\\.\\d*\",x)) > 0 else  re.findall(r\"\\d+\\.?\\d*\", x)[0] if len(re.findall(r\"\\d+\\.?\\d*\", x)) > 0 else 'other')\n",
    "    new['clear_osv'] = data['os_name'] + new['digit_osv']\n",
    "    data['clear_osv'] = new['clear_osv'].copy()\n",
    "    print('操作系统osv处理完毕')\n",
    "\n",
    "    # replace\n",
    "    replace = ['creative_is_jump', 'creative_is_download', 'creative_is_js', 'creative_is_voicead', 'creative_has_deeplink', 'app_paid']\n",
    "    for feat in replace:\n",
    "        data[feat] = data[feat].replace([False, True], [0, 1])\n",
    "    # labelencoder 转化\n",
    "    encoder = ['city', 'province', 'make', 'model', 'osv', 'os_name', 'adid', 'advert_id', 'orderid',\n",
    "               'advert_industry_inner', 'campaign_id', 'creative_id', 'app_cate_id', 'sim_ip',\n",
    "               'app_id', 'inner_slot_id', 'advert_name', 'f_channel', 'creative_tp_dnf', 'clear_model', 'clear_make', 'clear_osv']\n",
    "    lbl = LabelEncoder()\n",
    "    for feat in encoder:\n",
    "        lbl.fit(data[feat])\n",
    "        data[feat] = lbl.transform(data[feat])\n",
    "        \n",
    "    return data\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 后续组合特征，历史专户率，广告瀑光率特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "def combine_feature_time_feature(data):\n",
    "    lbl = LabelEncoder()\n",
    "    #组合特征\n",
    "    data['meiti_con_inner'] = data['app_id'].astype(str) + data['inner_slot_id'].astype(str)\n",
    "    data['meiti_con_inner'] = lbl.fit_transform(data['meiti_con_inner'])\n",
    "    data['meiti_con_inner_con_channel'] = data['app_id'].astype(str) + data['inner_slot_id'].astype(str) + data['f_channel'].astype(str)\n",
    "    data['meiti_con_inner_con_channel']  = lbl.fit_transform(data['meiti_con_inner_con_channel'] )\n",
    "    data['app_cate_con_adid'] = data['app_cate_id'].astype(str) + data['adid'].astype(str)\n",
    "    data['app_cate_con_adid'] = lbl.fit_transform(data['app_cate_con_adid'])\n",
    "    data['app_cate_con_meiti'] = data['app_cate_id'].astype(str) + data['app_id'].astype(str)\n",
    "    data['app_cate_con_meiti'] = lbl.fit_transform(data['app_cate_con_meiti'])\n",
    "    #加入\n",
    "    data['model_con_osv'] = data['model'].astype(str) + data['osv'].astype(str)\n",
    "    data['model_con_osv'] = lbl.fit_transform(data['model_con_osv'])\n",
    "    data['model_con_city'] = data['model'].astype(str) + data['city'].astype(str)\n",
    "    data['model_con_city'] = lbl.fit_transform(data['model_con_city'])\n",
    "\n",
    "    data['day'] = data['time'].apply(lambda x : int(time.strftime(\"%d\", time.localtime(x))))\n",
    "    data['hour'] = data['time'].apply(lambda x : int(time.strftime(\"%H\", time.localtime(x)))) \n",
    "    # 历史点击率\n",
    "    # 时间转换\n",
    "    data['period'] = data['day']\n",
    "    data['period'][data['period']<27] = data['period'][data['period']<27] + 31\n",
    "\n",
    "    for feat_1 in ['advert_id','advert_industry_inner','advert_name','campaign_id', 'creative_height',\n",
    "                   'creative_tp_dnf', 'creative_width', 'province', 'f_channel']:\n",
    "        gc.collect()\n",
    "        res=pd.DataFrame()\n",
    "        temp=data[[feat_1,'period','click']]\n",
    "        for period in range(27,35):\n",
    "            if period == 27:\n",
    "                count=temp.groupby([feat_1]).apply(lambda x: x['click'][(x['period']<=period).values].count()).reset_index(name=feat_1+'_all')\n",
    "                count1=temp.groupby([feat_1]).apply(lambda x: x['click'][(x['period']<=period).values].sum()).reset_index(name=feat_1+'_1')\n",
    "            else: \n",
    "                count=temp.groupby([feat_1]).apply(lambda x: x['click'][(x['period']<period).values].count()).reset_index(name=feat_1+'_all')\n",
    "                count1=temp.groupby([feat_1]).apply(lambda x: x['click'][(x['period']<period).values].sum()).reset_index(name=feat_1+'_1')\n",
    "            count[feat_1+'_1']=count1[feat_1+'_1']\n",
    "            count.fillna(value=0, inplace=True)\n",
    "            count[feat_1+'_rate'] = round(count[feat_1+'_1'] / count[feat_1+'_all'], 5)\n",
    "            count['period']=period\n",
    "            count.drop([feat_1+'_all', feat_1+'_1'],axis=1,inplace=True)\n",
    "            count.fillna(value=0, inplace=True)\n",
    "            res=res.append(count,ignore_index=True)\n",
    "        print(feat_1,' over')\n",
    "        data = pd.merge(data,res, how='left', on=[feat_1,'period'])\n",
    "        \n",
    "    #广告的曝光率 提升5个w\n",
    "    adid_nuq=['model','make','os','city','province', 'f_channel','app_id','carrier','nnt', 'devtype',\n",
    "             'app_cate_id','inner_slot_id']\n",
    "    for fea in tqdm_notebook(adid_nuq):\n",
    "        gp1=data.groupby('adid')[fea].nunique().reset_index().rename(columns={fea:\"adid_%s_nuq_num\"%fea})\n",
    "        gp2=data.groupby(fea)['adid'].nunique().reset_index().rename(columns={'adid':\"%s_adid_nuq_num\"%fea})\n",
    "        data=pd.merge(data,gp1,how='left',on=['adid'])\n",
    "        data=pd.merge(data,gp2,how='left',on=[fea])   \n",
    "        gc.collect()\n",
    "        \n",
    "    return data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "make变量处理完毕\n",
      "model 变量处理完毕\n",
      "操作系统osv处理完毕\n"
     ]
    }
   ],
   "source": [
    "#初步处理\n",
    "data = process(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "advert_id  over\n",
      "advert_industry_inner  over\n",
      "advert_name  over\n",
      "campaign_id  over\n",
      "creative_height  over\n",
      "creative_tp_dnf  over\n",
      "creative_width  over\n",
      "province  over\n",
      "f_channel  over\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "169efe7f5e9547129ccae36203910bda",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=12), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "### 后续处理\n",
    "data = combine_feature_time_feature(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import pickle\n",
    "##存储中间特征矩阵便于再次访问\n",
    "with open('../data/temp.pkl', 'wb') as file:\n",
    "    pickle.dump(data, file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   adid  advert_id  advert_industry_inner  advert_name  app_cate_id  app_id  \\\n",
      "0   553          1                     17           25            8     233   \n",
      "1    98          1                     17           25            9      17   \n",
      "2   190          2                     11           32            1     255   \n",
      "3  1072         33                     16            0            1     157   \n",
      "4    10          1                     17           25            4       5   \n",
      "5   522         12                     21           20            4     162   \n",
      "6  1536         32                      6            6            1     138   \n",
      "7   553          1                     17           25            8     233   \n",
      "8  1072         33                     16            0            1     157   \n",
      "9  1126          1                     17           25            1     255   \n",
      "\n",
      "   app_paid  campaign_id  carrier  city             ...              \\\n",
      "0         0            1        1    78             ...               \n",
      "1         0            1        3   234             ...               \n",
      "2         0            0        3   108             ...               \n",
      "3         0           38        0    86             ...               \n",
      "4         0            1        1    82             ...               \n",
      "5         0           15        1   200             ...               \n",
      "6         0           31        1    73             ...               \n",
      "7         0            1        1     2             ...               \n",
      "8         0           38        0   276             ...               \n",
      "9         0            1        1   164             ...               \n",
      "\n",
      "   adid_carrier_nuq_num  carrier_adid_nuq_num  adid_nnt_nuq_num  \\\n",
      "0                     1                  2054                 3   \n",
      "1                     3                  1248                 5   \n",
      "2                     3                  1248                 2   \n",
      "3                     1                   188                 4   \n",
      "4                     3                  2054                 2   \n",
      "5                     3                  2054                 3   \n",
      "6                     1                  2054                 2   \n",
      "7                     1                  2054                 3   \n",
      "8                     1                   188                 4   \n",
      "9                     3                  2054                 2   \n",
      "\n",
      "   nnt_adid_nuq_num  adid_devtype_nuq_num  devtype_adid_nuq_num  \\\n",
      "0              2032                     1                  2091   \n",
      "1              2032                     2                  2091   \n",
      "2              2032                     1                  2091   \n",
      "3              2032                     1                  2091   \n",
      "4               812                     1                  2091   \n",
      "5              2032                     1                  2091   \n",
      "6              2032                     1                  2091   \n",
      "7              2032                     1                  2091   \n",
      "8              2032                     1                  2091   \n",
      "9              2032                     1                  2091   \n",
      "\n",
      "   adid_app_cate_id_nuq_num  app_cate_id_adid_nuq_num  \\\n",
      "0                         1                       674   \n",
      "1                         1                       697   \n",
      "2                         1                      1010   \n",
      "3                         1                      1010   \n",
      "4                         1                       822   \n",
      "5                         3                       822   \n",
      "6                         2                      1010   \n",
      "7                         1                       674   \n",
      "8                         1                      1010   \n",
      "9                         1                      1010   \n",
      "\n",
      "   adid_inner_slot_id_nuq_num  inner_slot_id_adid_nuq_num  \n",
      "0                           1                          89  \n",
      "1                           1                          55  \n",
      "2                           1                          65  \n",
      "3                          10                           5  \n",
      "4                           1                          30  \n",
      "5                          11                          31  \n",
      "6                           5                         300  \n",
      "7                           1                          89  \n",
      "8                          10                           5  \n",
      "9                           1                          65  \n",
      "\n",
      "[10 rows x 81 columns]\n"
     ]
    }
   ],
   "source": [
    "## 读取特征矩阵\n",
    "with open('../data/temp.pkl', 'rb') as file:\n",
    "    data = pickle.load(file)\n",
    "\n",
    "print(data.head(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>adid</th>\n",
       "      <th>advert_id</th>\n",
       "      <th>advert_industry_inner</th>\n",
       "      <th>advert_name</th>\n",
       "      <th>app_cate_id</th>\n",
       "      <th>app_id</th>\n",
       "      <th>app_paid</th>\n",
       "      <th>campaign_id</th>\n",
       "      <th>carrier</th>\n",
       "      <th>city</th>\n",
       "      <th>...</th>\n",
       "      <th>adid_carrier_nuq_num</th>\n",
       "      <th>carrier_adid_nuq_num</th>\n",
       "      <th>adid_nnt_nuq_num</th>\n",
       "      <th>nnt_adid_nuq_num</th>\n",
       "      <th>adid_devtype_nuq_num</th>\n",
       "      <th>devtype_adid_nuq_num</th>\n",
       "      <th>adid_app_cate_id_nuq_num</th>\n",
       "      <th>app_cate_id_adid_nuq_num</th>\n",
       "      <th>adid_inner_slot_id_nuq_num</th>\n",
       "      <th>inner_slot_id_adid_nuq_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>553</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>25</td>\n",
       "      <td>8</td>\n",
       "      <td>233</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>78</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>2054</td>\n",
       "      <td>3</td>\n",
       "      <td>2032</td>\n",
       "      <td>1</td>\n",
       "      <td>2091</td>\n",
       "      <td>1</td>\n",
       "      <td>674</td>\n",
       "      <td>1</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>98</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>25</td>\n",
       "      <td>9</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>234</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>1248</td>\n",
       "      <td>5</td>\n",
       "      <td>2032</td>\n",
       "      <td>2</td>\n",
       "      <td>2091</td>\n",
       "      <td>1</td>\n",
       "      <td>697</td>\n",
       "      <td>1</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>190</td>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "      <td>32</td>\n",
       "      <td>1</td>\n",
       "      <td>255</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>108</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>1248</td>\n",
       "      <td>2</td>\n",
       "      <td>2032</td>\n",
       "      <td>1</td>\n",
       "      <td>2091</td>\n",
       "      <td>1</td>\n",
       "      <td>1010</td>\n",
       "      <td>1</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1072</td>\n",
       "      <td>33</td>\n",
       "      <td>16</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>157</td>\n",
       "      <td>0</td>\n",
       "      <td>38</td>\n",
       "      <td>0</td>\n",
       "      <td>86</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>188</td>\n",
       "      <td>4</td>\n",
       "      <td>2032</td>\n",
       "      <td>1</td>\n",
       "      <td>2091</td>\n",
       "      <td>1</td>\n",
       "      <td>1010</td>\n",
       "      <td>10</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>17</td>\n",
       "      <td>25</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>82</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>2054</td>\n",
       "      <td>2</td>\n",
       "      <td>812</td>\n",
       "      <td>1</td>\n",
       "      <td>2091</td>\n",
       "      <td>1</td>\n",
       "      <td>822</td>\n",
       "      <td>1</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 81 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   adid  advert_id  advert_industry_inner  advert_name  app_cate_id  app_id  \\\n",
       "0   553          1                     17           25            8     233   \n",
       "1    98          1                     17           25            9      17   \n",
       "2   190          2                     11           32            1     255   \n",
       "3  1072         33                     16            0            1     157   \n",
       "4    10          1                     17           25            4       5   \n",
       "\n",
       "   app_paid  campaign_id  carrier  city             ...              \\\n",
       "0         0            1        1    78             ...               \n",
       "1         0            1        3   234             ...               \n",
       "2         0            0        3   108             ...               \n",
       "3         0           38        0    86             ...               \n",
       "4         0            1        1    82             ...               \n",
       "\n",
       "   adid_carrier_nuq_num  carrier_adid_nuq_num  adid_nnt_nuq_num  \\\n",
       "0                     1                  2054                 3   \n",
       "1                     3                  1248                 5   \n",
       "2                     3                  1248                 2   \n",
       "3                     1                   188                 4   \n",
       "4                     3                  2054                 2   \n",
       "\n",
       "   nnt_adid_nuq_num  adid_devtype_nuq_num  devtype_adid_nuq_num  \\\n",
       "0              2032                     1                  2091   \n",
       "1              2032                     2                  2091   \n",
       "2              2032                     1                  2091   \n",
       "3              2032                     1                  2091   \n",
       "4               812                     1                  2091   \n",
       "\n",
       "   adid_app_cate_id_nuq_num  app_cate_id_adid_nuq_num  \\\n",
       "0                         1                       674   \n",
       "1                         1                       697   \n",
       "2                         1                      1010   \n",
       "3                         1                      1010   \n",
       "4                         1                       822   \n",
       "\n",
       "   adid_inner_slot_id_nuq_num  inner_slot_id_adid_nuq_num  \n",
       "0                           1                          89  \n",
       "1                           1                          55  \n",
       "2                           1                          65  \n",
       "3                          10                           5  \n",
       "4                           1                          30  \n",
       "\n",
       "[5 rows x 81 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
